#!/usr/bin/python3
# -*- coding: utf-8 -*-

import pandas as pd
import numpy  as np
import talib


def signal(*args):

    # OSC 指标
    """
    N=40
    M=20
    OSC=CLOSE-MA(CLOSE,N)
    OSCMA=MA(OSC,M)
    OSC 反映收盘价与收盘价移动平均相差的程度。如果 OSC 上穿/下 穿 OSCMA 则产生买入/卖出信号。
    """
    df = args[0]
    n = args[1]
    factor_name = args[2]

    df['ma'] = df['close'].rolling(2 * n, min_periods=1).mean()
    df['OSC'] = df['close'] - df['ma']
    df[factor_name] = df['OSC'].rolling(n, min_periods=1).mean()

    del df['ma']
    del df['OSC']

    return df